package net.entelijan.cobean.examples.lit;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Window;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import net.entelijan.cobean.examples.util.ExamplesUtil;
import net.miginfocom.swing.MigLayout;

public class EditAuthorDialog extends JDialog {

	private JTextField nameTextField = new JTextField();
	private JTextField nameFailureTextField = createFailureTextField();
	private JComboBox languageComboBox = new JComboBox();
	private JComboBox countryComboBox = new JComboBox();
	private JTextField birthdayTextField = new JTextField();
	private JTextField birthdayFailureTextField = createFailureTextField();

	private JButton okButton = new JButton("OK");
	private JButton cancelButton = new JButton("Cancel");

	private static final long serialVersionUID = 1L;

	public EditAuthorDialog(Window owner) {
		super(owner);
		setTitle("Lit Author");
		setSize(600, 250);
		Container cp = getContentPane();
		cp.setLayout(new BorderLayout());
		{
			JPanel cent = new JPanel();
			cent.setLayout(new MigLayout());
			String inputConstr = "w 200:max:max";
			String failureConstr = "w 300:200:200";

			cent.add(new JLabel("Name"));
			cent.add(this.nameTextField, inputConstr);
			cent.add(this.nameFailureTextField, failureConstr + ", wrap");

			cent.add(new JLabel("Language"));
			cent.add(this.languageComboBox, inputConstr);
			cent.add(new JPanel(), "wrap");

			cent.add(new JLabel("Country"));
			cent.add(this.countryComboBox, inputConstr);
			cent.add(new JPanel(), "wrap");

			cent.add(new JLabel("Birthday"));
			cent.add(this.birthdayTextField, inputConstr);
			cent.add(this.birthdayFailureTextField, failureConstr + ", wrap");

			cent.add(new JPanel(), "h max, w max, span 3, wrap");
			cent.add(ExamplesUtil.createButtonsPanel(100, this.okButton,
					this.cancelButton), "w max, span 3, wrap");

			cp.add(cent, BorderLayout.CENTER);
		}
		cp.add(createTop(), BorderLayout.NORTH);
	}

	private JTextField createFailureTextField() {
		JTextField re = new JTextField();
		re.setBorder(null);
		re.setEditable(false);
		re.setForeground(Color.RED);
		return re;
	}

	private JLabel createTop() {
		JLabel re = new JLabel();
		re.setIcon(new ImageIcon(getClass().getClassLoader().getResource(
				"logo-lit-author.png")));
		re.setOpaque(false);
		return re;
	}

	public JTextField getNameTextField() {
		return nameTextField;
	}

	public void setNameTextField(JTextField nameTextField) {
		this.nameTextField = nameTextField;
	}

	public JComboBox getLanguageTextField() {
		return languageComboBox;
	}

	public void setLanguageTextField(JComboBox languageComboBox) {
		this.languageComboBox = languageComboBox;
	}

	public JComboBox getCountryComboBox() {
		return countryComboBox;
	}

	public void setCountryComboBox(JComboBox countryComboBox) {
		this.countryComboBox = countryComboBox;
	}

	public JTextField getBirthdayTextField() {
		return birthdayTextField;
	}

	public void setBirthdayTextField(JTextField birthdayTextField) {
		this.birthdayTextField = birthdayTextField;
	}

	public JComboBox getLanguageComboBox() {
		return languageComboBox;
	}

	public void setLanguageComboBox(JComboBox languageComboBox) {
		this.languageComboBox = languageComboBox;
	}

	public JButton getOkButton() {
		return okButton;
	}

	public void setOkButton(JButton okButton) {
		this.okButton = okButton;
	}

	public JButton getCancelButton() {
		return cancelButton;
	}

	public void setCancelButton(JButton cancelButton) {
		this.cancelButton = cancelButton;
	}

	public JTextField getNameFailureTextField() {
		return this.nameFailureTextField;
	}

	public void setNameFailureTextField(JTextField nameFailureTextField) {
		this.nameFailureTextField = nameFailureTextField;
	}

	public JTextField getBirthdayFailureTextField() {
		return this.birthdayFailureTextField;
	}

	public void setBirthdayFailureTextField(JTextField birthdayFailureTextField) {
		this.birthdayFailureTextField = birthdayFailureTextField;
	}

}
